home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Review 28
/
Creative-Review-CD-ROM-28.iso
/
pc
/
kungfu
/
assets
/
game.dir
/
00036_Script_player class
< prev
next >
Wrap
Text File
|
1997-08-08
|
12KB
|
514 lines
-- player class method
-- --------------------------------------------------
property ancestor
property repeatflag
property priorityindex
property repeatindex
property bounceindex
property score
property lives
property fullhealth
property victory
property walkon
-- --------------------------------------------------
global gkey
global gjoystick
global gsound
global gcell
global gscore
global ghealth
global gstar
global glife
global ggame
global gboss
-- ==================================================
-- new method
-- --------------------------------------------------
on new me
minit me
return me
end mnew
-- ==================================================
-- minit method
-- --------------------------------------------------
on minit me
-- put "in minit player"
set fullhealth = 290
set score = 0
set priorityindex = data2list ( "move priority data" )
set repeatindex = data2list ( "move repeat data" )
set bounceindex = data2list ( "bounce data" )
set props = [:]
setaprop props, #health, fullhealth
setaprop props, #type, #player
setaprop props, #data, #player
set animdata = data2list ( "player anim data" )
setaprop props, #animdata , animdata
setaprop props, #drawdata , [ #channel : 18 ]
set ancestor = new ( script "actor class" , props )
set lives = 4
set victory = new ( script "victory class" , ancestor )
set walkon = new ( script "walkon class" , ancestor )
-- put "out minit player"
end minit
-- ==================================================
-- mdispose me
-- --------------------------------------------------
on mdispose me
-- put "in mdispose player class"
mdispose ancestor
set ancestor = 0
set priorityindex = 0
set repeatindex = 0
-- put "in mdispose player class"
end mdispose me
-- ==================================================
-- mkeydown method
-- --------------------------------------------------
on mkeydown me , thekey
-- put "* in mkeydown player: " thekey
set the nextmove of me = mkeytomove ( me, thekey )
set the nextmoveflag of me = true
-- put "(the nextmoveflag of me): " , (the nextmoveflag of me)
-- put "(the nextmove of me): " , (the nextmove of me)
-- put "* out mkeydown player: "
end mkeydown
-- ==================================================
-- mjoystick method
-- -------------------------------------------------
on mjoystick me, newdirection
-- put "in mjoystick player: "
set joyflag = false
if repeatflag or (the nextmoveflag of me) then
if not ( newdirection = the direction of me ) then set joyflag = true
else set joyflag = true
if joyflag then
set the nextmove of me = mkeytomove ( me, newdirection )
set the nextmoveflag of me = true
end if
-- put "out mjoystick player: "
end mjoystick
-- ==================================================
-- manimfinish method
-- --------------------------------------------------
on manimfinish me
-- put "in manimfinish: "
-- put "(the nextmoveflag of me): " , (the nextmoveflag of me)
-- put "(the nextmove of me): " , (the nextmove of me)
mmovefinish ( me )
if mcheckstun ( me ) then return
if (the nextmoveflag of me) then
set newmove = (the nextmove of me)
set the nextmoveflag of me = false
set newmove = mcheck ( me, newmove )
mmove gsound, #player, mmovetokey ( me, newmove )
else
-- check if we should autorepeat
-- either the joystick or combat keys
-- comparing priorities of each ones' suggested move
set keymove = mkeytomove ( me, ( mgetlatest ( gkey ) ) )
set joymove = mkeytomove ( me, ( mgetlatest ( gjoystick ) ) )
set keypriority = getaprop ( priorityindex , keymove )
set joypriority = getaprop ( priorityindex , joymove )
if joypriority > keypriority then
set newmove = joymove
else
if getaprop ( repeatindex , keymove ) then set newmove = keymove
else set newmove = mkeytomove ( me , #idle )
end if
set newmove = mcheck ( me, newmove )
end if
msetcurrentmove me, newmove
-- put "out manimfinish: "
end manimfinish
-- ==================================================
-- mstart method
-- --------------------------------------------------
on mstart me
-- put "in start player"
set the nextmove of me = 0
set the nextmoveflag of me = false
set the cell of me = - 4
set the direction of me = #right
msetcurrentmove me, #walkright
mbatchadd ( gcell, the cell of me, me)
set theloch = ( mcell2screen ( gcell, the cell of me ) )
set theloc = point ( theloch, mgetfloor ( gcell ) )
set offset = ( mgetstartoffset ( gcell, the direction of me , #player ) )
msetloc ( me, theloc + offset )
mwalkon walkon
mdraw glife
mdraw gscore
mset ghealth, ( the health of me )
mforcedraw ghealth
-- put "out start player"
end mstart me
-- ==================================================
-- mwalkonfinish method
-- --------------------------------------------------
on mwalkonfinish me
-- put "in mwalkonfinish player"
mbatchadd ( gcell, the cell of me, me)
msetcurrentmove me, #idleright
mforcedraw ghealth
-- put "out mwalkonfinish player"
end mwalkonfinish me
-- ==================================================
-- mhurt method
-- --------------------------------------------------
on mhurt me , attackmove, starloc
-- put "in mhurt"
set flag = mcheckhurt ( me , attackmove, starloc )
mset ghealth, ( the health of me )
-- put "out mhurt"
return flag
end mhurt
-- ==================================================
-- mhit method
-- --------------------------------------------------
on mhit me, theloc
-- put "in mhit player"
if ilk ( theloc, #point ) then
if ( mgetcurrentkey ( me ) = #bounce ) then
mstart gstar, ( the data of me ), ( the screenloc of me + theloc )
else if mhit ( ancestor, theloc ) then
-- put "hit baddy/boss"
end if
else
mdie me
end if
-- put "out mhit player"
end mhit
-- ==================================================
-- mbaddydead method
-- --------------------------------------------------
on mbaddydead me
-- put "in mbaddydead"
set score = score + 2
mset gscore, score
-- put "out mbaddydead"
end mbaddydead me
-- ==================================================
-- mbossdead method
-- --------------------------------------------------
on mbossdead me
-- put "in mbossdead"
set score = score + 20
mset gscore, score
-- put "out mbossdead"
end mbossdead me
-- ==================================================
-- mdie method
-- --------------------------------------------------
on mdie me
-- put "in mdie player"
mabort me
set lives = lives - 1
if lives < 0 then
hendgame
go frame "lose"
abort
end if
mset glife, lives
set the health of me = fullhealth
mset ghealth, ( the health of me )
set newkey = #birth
set newmove = mkeytomove ( me, newkey )
msetcurrentmove ( me , newmove )
-- put "out mdie player"
end mdie
-- ==================================================
-- mcheck method
-- --------------------------------------------------
on mcheck me, newmove
-- put "in mcheck player class :"
-- we check that the player isnt walking into another actor
-- we check that the player isnt walking offscreen
-- we bounce back jumping offscreen players
case newmove of
#walkleft:
set who = mcheck ( gcell, ( the cell of me ) , #left )
if not ( count ( who ) = 0 ) then set newmove = #idleleft
if ( the cell of me ) < 4 then set newmove = #idleleft
#walkright:
set who = mcheck ( gcell, ( the cell of me ) , #right )
if not ( count ( who ) = 0 ) then set newmove = #idleright
if ( the cell of me ) > 26 then set newmove = #idleright
#jumpleft:
if ( the cell of me ) < 10 then set newmove = #idleleft
else if ( the type of ggame = #boss ) then set newmove = mbounce ( me , newmove )
#jumpright:
if ( the cell of me ) > 19 then set newmove = #idleright
else if ( the type of ggame = #boss ) then set newmove = mbounce ( me , newmove )
end case
return newmove
-- put "out mcheck player class :"
end mcheck
-- ==================================================
-- mbounce method
-- --------------------------------------------------
on mbounce me, newmove
-- put "in mbounce player"
set distance = ( the cell of gboss - the cell of me )
case sense ( distance ) of
1 :
if ( the direction of me = #left ) then return newmove
-1 :
if ( the direction of me = #right ) then return newmove
end case
if abs (distance) = 12 then
case ( the direction of me ) of
#left: set walkcell = the cell of me - 8
#right: set walkcell = the cell of me + 11
end case
if count ( mget ( gcell, walkcell ) ) then
set distance = 11
end if
end if
set thelist = getaprop ( bounceindex , ( the direction of me ) )
set bounce = getaprop ( thelist , abs (distance) )
-- put "bounce: " , bounce
-- put "distance: " , abs (distance)
if voidp ( bounce ) then return newmove
else return bounce
-- put "out mbounce player"
end mbounce
-- ==================================================
-- mcheckstun method
-- --------------------------------------------------
on mcheckstun me
-- put "in mcheckstun player"
if ( mgetcurrentkey ( me ) = #jump ) then
set who = mbatchcheck ( gcell , ( the cell of me ), [ me ] )
if count ( who ) then
repeat with baddy in who
set the health of baddy = 0
mhurt baddy , ( the currentmove of me ), 0
end repeat
mstun me
return true
end if
else if ( mgetcurrentkey ( me ) = #bounce ) then
mstun me
return true
end if
-- put "out mcheckstun player"
return false
end mcheckstun
-- ==================================================
-- stun method
-- --------------------------------------------------
on mstun me
set the health of me = the health of me - 50
mset ghealth, ( the health of me )
if the health of me <= 0 then
set nextkey = #die
mstartdie me
else set nextkey = #stun
set newmove = mkeytomove ( me, nextkey )
mmove gsound, #player, nextkey
-- put "stunned!: " , newmove
msetcurrentmove me, newmove
end mstun me
-- ==================================================
-- mdodamage method
-- --------------------------------------------------
on mdodamage me, thedamage
mset ghealth, the health of me
mdamage me, thedamage
end mdodamage
-- ==================================================
-- mvictory method
-- --------------------------------------------------
on mvictory me
-- put "in mvictory player"
mvictory victory
set bonus = mgetbonus ( ggame )
-- put "player bonus: " , bonus
if bonus then
set score = score + bonus
manimset gscore, score
end if
-- put "out mvictory player"
end mvictory